
#include <pic18.h>
#include "my_macros.h"
//#include "RF12B.h"
#include "SysClock.h"
//#include "hardware.h"
#include "UART.h"
#include "String.h"
#include "app.h"
//#include "Outputs.h"
//#include "Command.h"
#include "atd.h"
#include "printf.h"

#define   SERIAL_NUM_ADDRESS		0x600

//__EEPROM_DATA(0x01, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0xFF);
//__EEPROM_DATA(0x12, 0x34, 0x56, 0x78, 0x01, 0x00, 0x00, 0x80); //- !!! dont change: 0x12, 0x34, 0x56, 0x78


#if defined(SH_DEVICE__REMOTE_CONTROL) 	
__EEPROM_DATA(0x12, 0x34, 0x56, 0x78, 0x01, 0x00, 0x00, 0x10); //- !!! dont change: 0x12, 0x34, 0x56, 0x78
#elif defined(SH_DEVICE__SWITCH)
__EEPROM_DATA(0x12, 0x34, 0x56, 0x78, 0x01, 0x00, 0x00, 0x30); //- !!! dont change: 0x12, 0x34, 0x56, 0x78
#else
__EEPROM_DATA(0x12, 0x34, 0x56, 0x78, 0x01, 0x00, 0x00, 0x50); //- !!! dont change: 0x12, 0x34, 0x56, 0x78
#endif


void GetSerNum ( void )
{
/* 	far const unsigned long *p = NULL; */
/* 	p = (far const unsigned long*)SERIAL_NUM_ADDRESS; */
	
/* 	const unsigned long *p; */
/* 	p = (const unsigned long*)SERIAL_NUM_ADDRESS; */
/* 	SerNum = *p; */
	//SerNum = 0x12345678;
	//SerNum = 0x51525354;
	//SerNum = 0x01020304;
	SerNum =  (unsigned long)EEPROM_READ(4);
	SerNum |= (unsigned long)EEPROM_READ(5)<<8;
	SerNum |= (unsigned long)EEPROM_READ(6)<<16;
	SerNum |= (unsigned long)EEPROM_READ(7)<<24;
}

void init_device ( void )
{
	PORTA = 0;
	PORTB = 0;
	PORTC = 0;

	TRISB4 = 0;
	TRISB5 = 0;

	/* Comparators off */
	CM2CON0 = 0;
	CM2CON1 = 0;
	CM1CON0 = 0;
	
	ANSEL = 0;						  /* all pins as digit */
	ANSELH = 0;						  /* all pins as digit */

	OSCCON = 0x70;					  /* 16Mhz */

	InitUART();

	app_init();						  /* must be first */

//	Out_Init();

	SysClock_Init();

//	RF_Init();

	ainp_init();
//	Inputs_Init();
//	Cmd_Init();

	GetSerNum();

	GIE = TRUE;

	//SendStatus();
}

/* Serialization */
//#pragma psect text%%u=Ser_Num
/* #pragma psect text%%u=Ser_Num */
/* void Ser_Num ( void ) */
/* { */
/*  #asm */
/* 	retlw 0x12 */
/* 	retlw 0x34 */
/* 	retlw 0x56 */
/* 	retlw 0x78 */
/*  #endasm */

/* } */

/* //#pragma psect text%%u=Ser_Num */
/* #pragma psect text%%=Ser_Num */
/* void Ser_Num ( void ) */
/* { */
/* 	asm(	"retlw 0x12, retlw 0x34, retlw 0x56, retlw 0x78"); */
/* } */

